<?php
error_reporting(0);
$dbserver   = "127.0.0.1";
$dbusername = "root";
$dbpassword = "";

//接收get参数
if ($_GET['db'] == '') {
	$database = 'ixdcw_v2';
} else {
	$database = strval($_GET['db']);
}

$mysql_conn = @mysql_connect("$dbserver", "$dbusername", "$dbpassword") or die("Mysql connect is error.");

mysql_select_db($database, $mysql_conn);
$result = mysql_list_tables($database, $mysql_conn);
mysql_query('SET NAMES utf8', $mysql_conn);
$allDict = '';
while ($tableList = mysql_fetch_array($result)) {
	$table        = $tableList[0];
	$sql = "
		SELECT * FROM INFORMATION_SCHEMA.COLUMNS
		WHERE table_name = '$table'
			AND table_schema = '$database'";
	$field_result = mysql_query($sql, $mysql_conn);
	$dict = "<table>";
	$dict .= "<caption>{$table}</caption>";
	$dict .= "<tr><th>字段名</th><th>数据类型</th><th>默认值</th><th>字符编码</th><th>备注</th></tr>";
	while ($f = mysql_fetch_array($field_result)) {
		$dict .= "<tr>";
		$dict .= "<td class=\"c1\">{$f['COLUMN_NAME']}</td>";
		$dict .= "<td class=\"c2\">{$f['COLUMN_TYPE']}</td>";
		$dict .= "<td class=\"c3\">{$f['COLUMN_DEFAULT']}</td>";
		$dict .= "<td class=\"c4\">{$f['COLLATION_NAME']}</td>";
		$dict .= "<td class=\"c5\">{$f['COLUMN_COMMENT']}</td>";
		$dict .= "</tr>";

	}
	$dict .= "</table>";
	$allDict .= $dict;
}
mysql_close($mysql_conn);
?>
<!DOCTYPE HTML>
<html lang="zh-CN">
<head>
	<meta charset="UTF-8">
	<title>Ixdcw 数据字典</title>
	<style>
        table{ border-collapse:collapse;border:1px solid #CCC;background:#efefef;width:100%; margin-bottom:1em;}
		table th{ text-align:left; font-weight:bold; padding:.5em 2em .5em .75em; line-height:1.6em; font-size:12px; border:1px solid #CCC;}
		table td{ padding:.5em .75em; line-height:1.6em; font-size:12px; border:1px solid #CCC;background-color:#fff;}
		.c1{ width: 150px;}
		.c2{ width: 120px;}
		.c3{ width: 130px;}
		.c4{ width: 130px;}
		caption{ font-size:14px; font-weight:bold; line-height:2em; text-align:left; }
	</style>
</head>
<body>
<?php echo $allDict; ?>
</body>
</html>




